<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>CSDN</title>
</head>
<body>
<div id="blog">
    <table border="1" cellspacing="0">
        <thead>
        <tr align="center" height="40">
            <th width="300">标题</th>
            <th width="850">简介</th>
            <th width="50">点赞</th>
            <th width="90">发布日期</th>
            <th width="100">作者</th>
        </tr>
        </thead>
     <tr v-for="blog in blogs" height="40">
         <td>{{blog.title}}</td>
         <td>{{blog.description}}</td>
         <td>{{blog.praise}}</td>
         <td>{{blog.date}}</td>
         <td>{{blog.username}}</td>
         <td>
             <form action="./browse.html" method="get">
                 <input style="display: none" type="text" name="blogId" :value="blog.id">
                 <input type="submit" value="查看" >
             </form>
         </td>
     </tr>
    </table>
    <div align="center">
        <input type="button" value="上一页" onclick="up_click()"></input>
        <input type="button" value="下一页" onclick="down_click()"></input>
    </div>
</div>
</body>
</html>

<script src="../js/ajax.js"></script>
<script src="../js/vue.js"></script>

<script>

    window.onload=function getblog() {
        let currentPage=window.localStorage.getItem("page");
        let target_domain=localStorage.getItem("domain");
    new Vue({
        el:"#blog",
        data(){
            return{
                blogs:[]
            }
        },
        mounted(){
            let _this=this;
            ajax({
                method: "post",
                url: "../../blog",
                data: {
                    currentPage:currentPage,
                    domain: target_domain,
                    code:0
                },
                success: function (result) {
                    console.log(result);
                    _this.blogs=result;
                },
                error:function (result){
                    console.log(result);
                }
            })
        }
    })
    }
    function up_click(){
        let currentPage=window.localStorage.getItem("page");
        currentPage=currentPage-1;
        window.localStorage.setItem("page",currentPage.toString());
        window.location.href="./blog.html";
    }

    function down_click(){
        let currentPage=window.localStorage.getItem("page");
        currentPage=parseInt(currentPage)+1;
        window.localStorage.setItem("page",currentPage.toString());
        window.location.href="./blog.html";
    }
</script>